package com.lzy.mall.ware.controller;


import cn.hutool.core.collection.CollUtil;
import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.ware.entity.WmsPurchaseDetail;
import com.lzy.mall.ware.entity.WmsWareSku;
import com.lzy.mall.ware.service.WmsPurchaseDetailService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * (WmsPurchaseDetail)表控制层
 *
 * @author lzy
 * @since 2021-08-24 19:01:45
 */
@RestController
@RequestMapping("purchasedetail")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class WmsPurchaseDetailController {
    private final WmsPurchaseDetailService purchaseDetailService;

    @GetMapping("/list")
    public ResultUtils list(@RequestParam Map<String,Object> params){
        PageUtils page = purchaseDetailService.queryPage(params);
        return ResultUtils.ok().put("page",page);
    }

    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ware:wareinfo:info")
    public ResultUtils info(@PathVariable("id") Long id){
        WmsPurchaseDetail purchaseDetail = purchaseDetailService.getById(id);

        return ResultUtils.ok().put("purchaseDetail", purchaseDetail);
    }

    @PostMapping("/save")
    public ResultUtils save(@RequestBody WmsPurchaseDetail purchaseDetail){
        purchaseDetailService.save(purchaseDetail);
        return ResultUtils.ok();
    }

    @PostMapping("/update")
    public ResultUtils update(@RequestBody WmsPurchaseDetail purchaseDetail){
        purchaseDetailService.update(purchaseDetail);
        return ResultUtils.ok();
    }

    @PostMapping("/delete")
    public ResultUtils delete(@RequestBody Long[] ids){
        purchaseDetailService.removeBatch(CollUtil.toList(ids));
        return ResultUtils.ok();
    }
}
